<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateShopsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        // 商品
            Schema::dropIfExists('goods');
            Schema::create('goods', function (Blueprint $table) {
                $table->bigIncrements('id');
                $table->string('name')->comment('名称');
                $table->integer('class_id')->default(0)->comment('分类id');
//                $table->decimal('original_price', 8, 2)->default(0)->comment('默认原价');
//                $table->decimal('sell_price', 8, 2)->default(0)->comment('默认卖价');
                $table->integer('sell_number')->default(0)->comment('卖出数量');
                $table->integer('init_sell_number')->default(0)->comment('售卖初始数量');
                $table->json('info_images')->nullable()->comment('详情图片-json数据，后台也方便');
                $table->json('loop_images')->nullable()->comment('轮播图-json数据，后台也方便');
                $table->string('cover_img')->default('')->comment('封面图');
                $table->json('sku')->nullable()->comment('sku 后台辅助');
                # 加入拼团
                $table->integer('is_assemble')->default(2)->comment('是否加入拼团');
                $table->integer('start_time')->nullable()->comment('拼团时间');
                $table->integer('ent_time')->nullable()->comment('拼团时间');
                $table->boolean('on_sale')->default(false);
                $table->json('attribute_list')->nullable()->comment('其他属性 和价格无关联的，标签,特点')->nullable();
                # 拼团时间；
                $table->timestamps();
            });



        //sku
           Schema::dropIfExists('goods_sku');
            Schema::create('goods_sku', function (Blueprint $table) {
                $table->bigIncrements('id');
                $table->string('sku_number')->comment('sku_number')->nullable();
                $table->integer('goods_id')->comment('备注')->nullable();
                $table->json('attribute_list')->comment('属性json,用户选择属性在前端进行筛选匹配')->nullable();
                $table->decimal('sku_price', 8, 2)->default(0);
                $table->decimal('original_price', 8, 2)->default(0);
                $table->integer('stock')->default(0)->comment('库存');
                $table->boolean('is_default')->default(false)->comment('是否是默认，默认1');
                $table->timestamps();
            });

        // 规格表--辅助后台进行
            Schema::dropIfExists('goods_specs');
            Schema::create('goods_specs', function (Blueprint $table) {
                $table->bigIncrements('id');
                $table->integer('goods_id')->comment('商品id');
                $table->string('name')->default(0)->comment('规格名称');
                $table->integer('parent_id')->default(0)->comment('父级id');
                $table->integer('sort');
                # is_default
                $table->timestamps();
            });

        // 拼团
        Schema::dropIfExists('goods_assemble');
            Schema::create('goods_assemble', function (Blueprint $table) {
                $table->bigIncrements('id');
                $table->integer('goods_id')->comment('商城id')->nullable();
                $table->timestamp('start_time')->nullable()->comment('可拼团开始时间');
                $table->timestamp('end_time')->nullable()->comment('可拼团结束时间');
                $table->timestamps();
            });

        //用户发起的拼团
        Schema::dropIfExists('user_assemble');
        Schema::create('user_assemble', function (Blueprint $table) {
                $table->bigIncrements('id');
                $table->integer('goods_id')->comment('商品id')->nullable();
                $table->integer('user_id')->comment('用户id')->nullable();
                $table->timestamp('start_time')->nullable()->comment('拼团开始时间');
                $table->timestamp('end_time')->nullable()->comment('拼团结束时间');
                $table->timestamps();
            });
        // 用户参团
            Schema::dropIfExists('user_haveassemble');
            Schema::create('user_haveassemble', function (Blueprint $table) {
                $table->bigIncrements('id');
                $table->integer('goods_id')->comment('商品id')->nullable();
                $table->integer('user_assemble_id')->comment('用户团id')->nullable();
                $table->integer('user_id')->comment('用户id')->nullable();
                $table->timestamps();
            });

        // 商城--轮播图
          Schema::dropIfExists('goods_img');
            Schema::create('goods_img', function (Blueprint $table) {
                $table->bigIncrements('id');
                $table->integer('goods_id')->comment('商城id')->nullable();
                $table->string('img')->nullable()->comment('图片');
                $table->timestamps();
            });
        // 商城--分类
          Schema::dropIfExists('goods_class');
            Schema::create('goods_class', function (Blueprint $table) {
                $table->bigIncrements('id');
                $table->string('icon')->default('');
                $table->integer('parent_id')->default(0);
                $table->string('name')->nullable()->comment('分类名称');
                $table->integer('sort')->default(99)->comment('排序');
                $table->timestamps();
            });
        }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('users');
    }
}
